package assignment2;
//Author Mark Mckillion, Date Completed 09/12/2011

import java.awt.*;
import java.awt.geom.*;
import javax.swing.JPanel;

@SuppressWarnings("serial")
public class QueuePanel extends JPanel
{   /*The purpose of this class is to update jPanel1 in the QueueFrame class.
     *I will override paint component to display the current status of the stack
     *and will repaint it each time a change is by the action listeners.*/
    
    //Create integers which will be set to equal values in the QueueFrame.
    private int count;
    private int rear;
    
    //Create an instance of the queue which will be set to equal the queue in QueueFrame.
    @SuppressWarnings("rawtypes")
	private CircularArrayQueue myQueue;
    
    public void setRear(int num)
    {   //This set method allows the program to access the rear value in QueueFrame.
        rear = num;
    }
    
    public void setCount(int value)
    {   //This set method allows the program to access the count value in QueueFrame.
        count = value;
    }
    
    @SuppressWarnings("rawtypes")
	public CircularArrayQueue setQueue(CircularArrayQueue queue)
    {   //This set method allows the program to access the myQueue object in QueueFrame.
        myQueue = queue;
        return myQueue;
    }
    
    @Override
    public void paintComponent(Graphics g)
    {   //Override paint component to design my JPanel
        //Call too the super class.
        super.paintComponent(g);
        
        //Create instances of GUI design packages.
        Graphics2D g2 = (Graphics2D)g;
        BasicStroke pen = new BasicStroke(1F);
        
        //Set the colour and thickness of the lines.
        g2.setColor(Color.BLACK);
        g2.setStroke(pen);
        
        //Create the empty rectangles.
        g2.draw(new Rectangle2D.Double(10,160,90,30));
        g2.draw(new Rectangle2D.Double(110,160,90,30));
        g2.draw(new Rectangle2D.Double(210,160,90,30));
        g2.draw(new Rectangle2D.Double(310,160,90,30));
        g2.draw(new Rectangle2D.Double(410,160,90,30));
        
        //create the empty circles.
        g2.draw(new Ellipse2D.Float(35,80,50,30));
        g2.draw(new Ellipse2D.Float(135,80,50,30));
        g2.draw(new Ellipse2D.Float(235,80,50,30));
        g2.draw(new Ellipse2D.Float(335,80,50,30));
        g2.draw(new Ellipse2D.Float(435,80,50,30));
        
        //Draw a counter which shows the number of items in the queue.
        g2.drawString("Count: " + String.valueOf(count),450,220);
        
        //Create integers for the starting x and y coordinates.
        int yCoord = 20;
        int yCoordNum = 57;
        
        for(int i = 0; i < count; i++)
         {  /*this for loop draws the string value at the rear of the queue into 
             *the appropriate retangle by altering the xCoord and yCoord
             *integers. It also draws the memory value into the circle in the
             *same way.*/
            g2.drawString(String.valueOf(myQueue.toString(rear-i-1)),yCoord+(i*100),180);
            g2.drawString(String.valueOf(rear-i-1),yCoordNum+(i*100),100);
         }
     }
}
